<?php

namespace ctrl;

use model\ondutys;
use libs\view;

class onduty extends base
{
	private static $M;
	public static function Init()
	{
		parent::init();
		self::$M = new ondutys;
	}

	public static function index()
	{
		if (isset($_GET['list_json'])) {
			jsonList(self::$M->jsonPageSelect());
		} else {
			view::display();
		}
	}

	public static function add()
	{
		if (isset($_GET['view'])) {
			view::assign('onduty', null);
			view::assign('title', "添加值班");
			view::display("post");
		}
		if (isset($_GET['batchesadd'])) {
			view::assign('onduty', null);
			view::assign('title', "批量添加值班");
			view::display("post_batchesadd");
		}
		if (isset($_GET['batchespost'])) {
			$result = self::$M->insertDataBatch();
			Response(array('status' => $result['status'], 'info' => $result['msg']));
		}
		if (isset($_GET['addpost'])) {
			$result = self::$M->insertData();
			Response(array('status' => $result['status'], 'info' => $result['msg']));
		}
	}


	public static function edit()
	{
		if (isset($_GET['view'])) {
			$onduty = self::$M->findData();
			view::assign('onduty', $onduty);
			view::assign('title', "编辑值班");
			view::display("post");
		} elseif (isset($_GET['switchStatus'])) {
			if (self::$M->switchStatus()) Response(array('status' => 1, 'info' => '设置成功'));
		} else {
			$result = self::$M->updateData();
			Response(array('status' => $result['status'], 'info' => $result['msg']));
		}
	}

	public static function del()
	{
		if (self::$M->deleteOneData())
			Response(array('status' => 1, 'info' => '删除成功'));
		else
			Response(array('status' => 0, 'info' => '删除错误!'));
	}
}
